package com.superme.repository;


import com.superme.entity.PersonEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.List;


/**
 * Created by Administrator on 2018/1/19.
 * 贫血模型中的dao层
 */
public interface PersonRepo extends Repository<PersonEntity, Long> {



    PersonEntity findById(int id);
    /*
    注释的接口方法可以作为参考，如果就是简单的做查询的话都可以采用以下方式
     */
    //List<PersonEntity> findByNameAndAgeAndNicknameOrderByNameAscAllIgnoreCase(String Name, Integer Age, String Nickname);

    //List<PersonEntity> findByNameAndNickname(String Name,  String Nickname);

    //Page<PersonEntity> findByNameAndAgeAndNicknameOrderByNameAscAllIgnoreCase(String Name, Integer Age, String Nickname, Pageable pageable);

    Page<PersonEntity> findAll(Specification<PersonEntity> spec, Pageable pageable);

    Page<PersonEntity> findAll( Pageable pageable);
    PersonEntity save(PersonEntity entity);


    void deleteById(int id);

    /*
    可以在接口里边自定义SQL语句的函数，比如置有效无效可能用这种方法更合适
     */
    @Modifying
    @Query(nativeQuery = true,value = "DELETE FROM person WHERE id = :id")
    void deletePersonById(@Param("id") Integer id);

}
